package org.ruiyichen.guizhou.agr.ui.mineview.dropdownmenu;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import org.ruiyichen.guizhou.agr.R;

import java.util.List;

/**
 * @version 1.0
 */
public class SimpleDropdownAdapter extends BaseDropdownAdapter<KeyValue> {

    private int select = -1;

    public SimpleDropdownAdapter(Context context, List<KeyValue> list) {
        super(context, list);
    }

    @Override
    public View onCreateView(View convertView, ViewGroup parent, KeyValue data, int position) {
        Holder hold;
        if (convertView == null) {
            hold = new Holder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_drop_down, parent, false);
            hold.title = (TextView) convertView.findViewById(R.id.item_drop_down_title);
            convertView.setTag(hold);
        } else {
            hold = (Holder) convertView.getTag();
        }
        hold.title.setText(data.getValue());
        hold.title.setSelected(select == position);
        return convertView;
    }

    @Override
    public void selectItem(int position) {
        select = position;
        notifyDataSetChanged();
    }

    @Override
    public String getTitleString(int position) {
        return list.get(position).getValue();
    }

    class Holder {
        TextView title;
    }
}
